import React, { useEffect, useState } from 'react'
import { fetchPageTitle } from '@/server/common'
import { View, Text } from '@tarojs/components'
import Taro from '@tarojs/taro'
import './index.scss'
const SetTitleAuth = (props) => {
    const { children, type = 'home' } = props

    useEffect(() => {
        fetchTitle()
    }, [])
    const fetchTitle = (e) => {
        if (type) {

            fetchPageTitle({
                type
            }).then(e => {
                const { title } = e
                if (title) {
                    Taro.setNavigationBarTitle({
                        title: title, // 设置新标题
                        success: () => console.log('标题设置成功'),
                        fail: (err) => console.error('标题设置失败', err),
                    });
                }

            })
        }
    }
    return <View className='SetTitleAuth_box'>
        {children}
    </View>
}
export default SetTitleAuth